package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    // 自定义根据时间+类型统计用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{time} AND TYPE = #{type}")
    Integer findByTimeAndType(@Param("time") String time, @Param("type") String type);

    // 自定义根据时间统计用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{time}")
    Integer findByTime(String time);

    // 自定义次日留存用户数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{today}\n" +
            "AND user_id IN (SELECT  DISTINCT user_id FROM tb_log WHERE log_time = #{yesterday} AND TYPE ='0102')")
    Integer findByTodayAndYesterDay(@Param("today") String today, @Param("yesterday") String yesterday);

}